package selenium;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.util.List;

import static com.sun.jna.platform.FileUtils.*;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

public class hometask2 {

    @Test
    public static void simple() {

        //comparing selects
        WebDriver driver = new FirefoxDriver();
        driver.get("https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select");
       // List<String>




/*        WebDriver driver = new FirefoxDriver();
        driver.get("http://htmlbook.ru/html/select");
        Select dropdown = new Select(driver.findElement(By.cssSelector("select[name=select]")));
        Integer amount = dropdown.getOptions().size();
        assertTrue(dropdown.isMultiple());
        dropdown.selectByIndex(1);
        dropdown.selectByIndex(2);
        List<WebElement> selectedOptions = dropdown.getAllSelectedOptions();
        for (WebElement option : selectedOptions) {
            System.out.println(option.getText());
        }*/

        //maximize window

//         WebDriver driver = new FirefoxDriver();
//        driver.get("http://html5demos.com/drag");
//        driver.manage().window().setSize(new Dimension(800, 600));
//        driver.manage().window().maximize();

        // take a screenshot
//        WebDriver driver = new FirefoxDriver();
//        driver.get("http://html5demos.com/drag");
//
//        try {
//            File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
//            FileUtils.copyFile(screenshot, new File("c://screen.png"));
//        } catch (IOException e) {
//            e.printStackTrace();
//        }


//        WebDriver driver = new FirefoxDriver();
//        driver.get("http://html5demos.com/drag");
//        JavascriptExecutor js = (JavascriptExecutor) driver;
//        String string = (String) js.executeScript("return document.title");
//        System.out.println(string);


        //drag and drop test

//        driver.get("http://html5demos.com/drag");
//        WebElement source = driver.findElement(By.id("one"));
//        WebElement target = driver.findElement(By.id("bin"));
//
//        Actions builder = new Actions(driver);
//        builder.dragAndDrop(source,target).perform();


//        driver.get("http://ex.ua/");
//        WebElement textArea = driver.findElement(By.xpath("//a[@href='/search']/ancestor::table[@id='menu']"));
//        System.out.println(textArea.getText());
//        assertEquals(true, textArea.contains("Вхід"));








//        WebElement search = driver.findElement(By.xpath("//a[@href='/search']"));
//        WebElement menu = driver.findElement(By.xpath("//a[@href='/search']/ancestor::table[@id='menu']"));
//        WebElement followingItem = driver.findElement(By.xpath("//a[@href='/search']/preceding::a[1]"));
//        WebElement precedingItem = driver.findElement(By.xpath("//a[@href='/search']/preceding-sibling::a[1]"));
//
//        System.out.println(search.getText());
//        System.out.println(followingItem.getText());
//        System.out.println(precedingItem.getText());



//        driver.get("http://rozetka.com.ua/");
//        List <WebElement> imgs = driver.findElements(By.xpath("//img[@alt]"));
//        Integer imgsSize = imgs.size();
//        System.out.println(imgsSize);



//        List <WebElement> imgs = driver.findElements(By.cssSelector("img"));
//        Integer imgsSize = imgs.size();
//        System.out.println(imgsSize);
//        List <WebElement> imgsAlt = driver.findElements(By.cssSelector("img[alt]"));
//        Integer imgsAltSize = imgsAlt.size();
//        System.out.println(imgsAltSize);

//        List<WebElement> links = driver.findElements(By.tagName("a"));
//        System.out.println(links.size());
//        for (WebElement link : links) {
//            System.out.println(link.getAttribute("title"));
//            System.out.println(link.getText());
//        }

//        driver.findElement(By.xpath("//*[contains(text(), 'Телефоны, MP3, GPS')]"));
//        driver.findElement(By.linkText("Ноутбуки"));
//        driver.findElement(By.partialLinkText("GPS"));

//        driver.findElement(By.xpath("//*[contains(text(), 'Телефоны, MP3, GPS')]/ancestor::a")).click();
        driver.quit();

    }








}
